<?php

use yii\helpers\Html;
use yii\grid\GridView;

$this->title = Yii::t('app', 'Invoices');
$this->params['breadcrumbs'][] = $this->title;
?>
<style type="text/css">
    .cs1{margin:2px 5px;} 
</style>

<div class="invoice-index">

    <div class="box">
        <div class="box-header">
            <?= Html::a(Yii::t('app', 'Create Invoice'), ['create','product_id'=>$product_id], ['class' => 'btn btn-success']) ?>
        </div>
        <div class="box-body">
        <p>
             <?php echo $this->render('_search', ['model' => $searchModel]); ?>
        </p>
        <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'layout'  =>  "{items}\n{summary}\n{pager}",
            'columns' => [
                ['class' => 'yii\grid\SerialColumn'],

                [
                    'attribute' => 'product.code',
                    'headerOptions' => ['width' => '15%'],
                    'value' => function ($model) {
                            return $model->product->code;
                    },
                ],

                [
                    'attribute' => 'product.name',
                    'headerOptions' => ['width' => '15%'],
                    'value' => function ($model) {
                            return $model->product->name;
                    },
                ],
                
                [
                    'attribute' => 'code',
                    'headerOptions' => ['width' => '5%'],
                    'value' => function ($model) {
                            return $model->code;
                    },
                ],
               
                [
                    'attribute' => 'price',
                    'headerOptions' => ['width' => '5%'],
                    'value' => function ($model) {
                            return $model->price;
                    },
                ],
                [
                    'attribute' => 'pay_type',
                    'headerOptions' => ['width' => '5%'],
                    'value' => function ($model) {
                            return isset(Yii::$app->params['invoice_pay_type'][$model->pay_type])?Yii::$app->params['invoice_pay_type'][$model->pay_type]:'';
                        },
                ],

                [
                    'attribute' => 'status',
                    'headerOptions' => ['width' => '5%'],
                    'value' => function ($model) {
                            return isset(Yii::$app->params['status'][$model->status])?Yii::$app->params['status'][$model->status]:'';
                        },
                ],
               
                [
                    'attribute' => 'download_time',
                    'headerOptions' => ['width' => '10%'],
                    'value' => function ($model) {
                            return $model->download_time;
                    },
                ],
   
                [
                    'attribute' => 'payment_date',
                    'headerOptions' => ['width' => '10%'],
                    'value' => function ($model) {
                            return $model->payment_date;
                    },
                ],

                [
                  'attribute' => 'user_id',
                  'headerOptions' => ['width' => '5%'],
                  'value' => function($model){

                        return $model->userName;
                  }
                ],

                [
                    'label'=>'操作',
                    'headerOptions' => ['width' => '25%'],
                    'format'=>'raw',
                    'value' => function($model){

                        $url  = sprintf("/product/invoice/view?id=%d", $model->id); //查看
                        $url2  = sprintf("/product/invoice/update?id=%d", $model->id); //更新
                        $url3  = sprintf("/product/invoice/download?id=%d", $model->id); //下载

                        $str  = Html::a('查看',$url,['title' =>'查看','class'=>'btn btn-primary btn-xs cs1',]);

                        $str  .= Html::a('更新',$url2,['title' =>'更新','class'=>'btn btn-success btn-xs cs1',]);

                        $str  .= Html::a('下载',$url3,['title' =>'下载','class'=>'btn btn-warning btn-xs cs1',]);
                        
                        return $str;
                     }
                ],
            ],
        ]); ?>
        </div>
    </div>
</div>
